package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdOrderMonthVersionChangeStateVO;
import com.yunxi.otd.pojo.OtdOrderMonthVersionQueryVO;
import com.yunxi.otd.pojo.OtdOrderMonthVersionVO;
import com.yunxi.otd.service.OtdOrderMonthVersionDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 月排产需求订单版本管理 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-07-15
 */
@RestController
@RequestMapping("/admin/otd/month/version")
@Api(tags = "OTD:MONTHVERSION", description = "月排产需求订单版本管理接口")
public class OtdOrderMonthVersionController {

    @Autowired
    OtdOrderMonthVersionDubboService monthVersionDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(OtdOrderMonthVersionQueryVO queryVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil
            .ok(monthVersionDubboService.findPageByVO(queryVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "下拉框查询")
    public ApiResult list(OtdOrderMonthVersionVO otdOrderMonthVersionVO) {
        return ResponseUtil.ok(monthVersionDubboService.listByVo(otdOrderMonthVersionVO));
    }

    @PostMapping("/change")
    @ApiOperation(value = "状态变更")
    public ApiResult change(@RequestBody OtdOrderMonthVersionChangeStateVO changeStateVO) {
        return monthVersionDubboService.changeState(changeStateVO);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除版本")
    public ApiResult remove(@RequestBody List<String> ids) {
        return monthVersionDubboService.removeByIds(ids);
    }

    @PostMapping("/default")
    @ApiOperation(value = "设置默认版本")
    public ApiResult setDefault(@RequestBody Map<String,Object> map) {
        String id = (String)map.get("id");
        if (StringUtils.isEmpty(id)) {
            return ResponseUtil.fail(-1, "参数错误，ID不能为空！");
        }
        return monthVersionDubboService.setDefault((String) map.get("id"));
    }
}
